package com.baofu.paycore.service.validate.impl.refund;

import com.baofu.paycore.common.exception.ValidateException;
import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import com.baofu.paycore.service.facade.model.refund.req.RefundReqDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 退款参数校验
 *
 * @author tiger
 * @version 1.0.0 createTime: 14-12-9 下午3:43
 * @see AbstractPayValidate
 */
@Slf4j
@Component
public class RefundValidate extends AbstractPayValidate<RefundReqDTO> {

    /**
     * 退款交易金额校验
     *
     * @param amt             退款交易退款总金额
     * @param refundFeeAmt    退款交易退手续费金额
     * @param feeAmt          退款交易收手续费金额
     */
    public void validateRefund(Long amt, Long refundFeeAmt, Long feeAmt){

        if(null == amt ){
            log.error("退款交易金额校验异常");
            throw new ValidateException(PayCoreErrorCode.AMT_IS_NOT_IN_CONFORMITY);
        }

        if(null != refundFeeAmt && amt <= refundFeeAmt ){
            log.error("退款交易金额校验异常, amt:{}, refundFeeAmt:{}",amt, refundFeeAmt);
            throw new ValidateException(PayCoreErrorCode.AMT_IS_NOT_IN_CONFORMITY);
        }

        if(null != feeAmt && amt <= feeAmt ){
            log.error("退款交易金额校验异常, amt:{}, feeAmt:{}",amt, feeAmt);
            throw new ValidateException(PayCoreErrorCode.AMT_IS_NOT_IN_CONFORMITY);
        }
    }
}
